<div class="flex-wrap space-y-4 md:flex md:flex-nowrap md:space-y-0 md:space-x-10">
  <%= render 'shared/settings_nav' %>
  <div class="md:flex-grow">
    <div class="flex justify-between mb-4">
      <h1 class="text-4xl font-bold">Team</h1>
      <div class="flex items-center space-x-4">
        <% if can?(:create, User.new(account: current_account)) %>
          <%= link_to new_user_path, class: 'btn btn-primary btn-md gap-2', data: { turbo_frame: 'modal' } do %>
            <%= svg_icon('plus', class: 'w-6 h-6') %>
            <span>New User</span>
          <% end %>
        <% end %>
      </div>
    </div>
    <div class="overflow-x-auto">
      <table class="table w-full table-lg rounded-b-none overflow-hidden">
        <thead class="bg-base-200">
          <tr class="text-neutral uppercase">
            <th>
              Name
            </th>
            <th>
              Email
            </th>
            <th>
              Role
            </th>
            <th>
              Last session
            </th>
            <th class="text-right" width="1px">
            </th>
          </tr>
        </thead>
        <tbody>
          <% @users.each do |user| %>
            <tr scope="row">
              <td>
                <%= user.full_name %>
              </td>
              <td>
                <%= user.email %>
              </td>
              <td>
                <span class="badge badge-info badge-outline">
                  <%= user.role %>
                </span>
              </td>
              <td>
                <%= user.last_sign_in_at ? l(user.last_sign_in_at.in_time_zone(current_account.timezone), format: :short, locale: current_account.locale) : '-' %>
              </td>
              <td class="flex items-center space-x-2 justify-end">
                <% if can?(:update, user) %>
                  <%= link_to edit_user_path(user), class: 'btn btn-outline btn-xs', title: 'Edit', data: { turbo_frame: 'modal' } do %>
                    Edit
                  <% end %>
                <% end %>
                <% if can?(:destroy, user) && user != current_user %>
                  <%= button_to user_path(user), method: :delete, class: 'btn btn-outline btn-error btn-xs', title: 'Delete', data: { turbo_confirm: 'Are you sure?' } do %>
                    Remove
                  <% end %>
                <% end %>
              </td>
            </tr>
          <% end %>
        </tbody>
      </table>
    </div>
    <%= render 'shared/pagination', pagy: @pagy, items_name: 'users' %>
  </div>
</div>
